package edu.cmu.cs.stage3.alice.authoringtool.util;

public class CompoundUndoableRedoable implements ContextAssignableUndoableRedoable {

 protected java.util.ArrayList items = new java.util.ArrayList();
 protected Object context;

 public CompoundUndoableRedoable () {}

 public void setContext (Object context ) {
  this.context = context;
  }

 public void addItem (UndoableRedoable item ) {
  // System.out.println("CompoundUndoableRedoable.java: addItem(): item="+edu.cmu.cs.stage3.util.StrUtilities.getComponentName(item));
  if (item instanceof ChildChangeUndoableRedoable) { }
  items.add( item );
  }

 // Undo: the stack order (the last first)
 public void undo () {
  java.util.ListIterator iter = items.listIterator();
  while (iter.hasNext() ) { // get the last item
   iter.next();
   }
  while (iter.hasPrevious()) { // stack order: get the last item first
   edu.cmu.cs.stage3.alice.authoringtool.util.UndoableRedoable item = (edu.cmu.cs.stage3.alice.authoringtool.util.UndoableRedoable)iter.previous();
   item.undo(); // edu.cmu.cs.stage3.alice.authoringtool.util.ObjectArrayPropertyUndoableRedoable.undo()
   }
  }

 public void redo () {
  java.util.ListIterator iter = items.listIterator();
  while (iter.hasNext() ) {
   edu.cmu.cs.stage3.alice.authoringtool.util.UndoableRedoable item = (edu.cmu.cs.stage3.alice.authoringtool.util.UndoableRedoable)iter.next();
   item.redo();
   }
  }

 public Object getAffectedObject () {
  return this;
  }

 public Object getContext () {
  return context;
  }

 }
